package com.lzy.liujing.restaurant.dao;

import com.lzy.liujing.restaurant.entity.Goods;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created with IDEA
 * author:LiuJing
 * Date:2018/10/1
 * Time:23:36
 */
@Mapper
public interface GoodsDao{
    @Select("select * from r_goods")
    List<Goods> selectAll();

    @Select("<script> SELECT * from r_goods" +
            "<where>"+
            "<if test='typeState != null'>and type_state = #{typeState}</if> "+
            " <if test='soldState != null'>and sold_state = #{soldState}</if> "+
            " <if test='categoryId != null'>and category_id = #{categoryId}</if> " +
            " <if test='goodsName != null'>and goods_name = #{goodsName}</if> " +
            "</where>"+
            "</script>")
    List<Goods> findPage(Goods query);

    @Delete("delete from r_goods where goods_id =#{goodsId}")
    int delete(Integer id);

    @Insert("insert into r_goods ( goods_name, category_id, description, cost, price, discount, sold_count, store_count, type_state)values" +
            " (#{goodsName},#{categoryId},#{description}, " +
            " #{cost}, #{price},#{discount}, #{soldCount}, #{storeCount},#{typeState} )")
    int insert(Goods brand);
    @Update("update r_goods set goods_name = #{goodsName}, category_id = #{categoryId}," +
            " description = #{description} ,cost = #{cost},price = #{price}, " +
            " discount = #{discount} ,  sold_count = #{soldCount} ,store_count = #{storeCount} , " +
            " type_state = #{typeState} ,img_url=#{imgUrl} where goods_id = #{goodsId}")
    int update(Goods brand);

    @Select("SELECT * FROM r_goods WHERE goods_id = #{goodsId}")
    Goods getById(Integer id);

}
